home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
050
/
bix04.arc
/
SHOWHEX.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1986-11-01
|
2KB
|
62 lines
{TITLE: LOOKING AT VARIABLES IN HEX
You don't need to do it very often. When you do, nothing else will do.
Here's a handy-dandy little tool for peering into your TP program while
it's running.}
(***************************************************************************)
PROCEDURE HexDump (Target:BytePtr; Length:INTEGER);
{This procedure will dump, in hex, an area of memory <Length> long beginning
at <Target>. You must previously have defined "BytePtr" as a pointer to an
array of BYTE. The following will do it:
TYPE
Bytes = ARRAY[0..1] OF BYTE;
BytePtr = ^Bytes;
Call HexDump with the *ADDRESS* where the dump is to begin, and a length.
For example, to dump the contents of integer variable IntVar, do this:
HexDump(addr(IntVar),2);
Of course, you could have used a length greater than 2 if you wanted to dump
a larger area of memory.
Constant "Width" is the number of columns of display to use. 48 gets you 16
bytes of dump before a new line. You can change it to anything that suits.
All the dire warnings about none of this being guaranteed apply.
--Bob Brown
September, 1986
}
CONST
Width = 48;
Hexes: ARRAY[0..15] OF CHAR = '0123456789ABCDEF';
VAR
I: INTEGER;
LineSize: INTEGER;
Left: BYTE;
Right: BYTE;
LeftC: CHAR;
RightC: CHAR;
BEGIN {HexDump}
WRITELN('');
LineSize := 0;
FOR I := 0 to Length-1 DO
BEGIN
Right := Target^[I] AND $0F;
Left := Target^[I] SHR 4;
LeftC := Hexes[Left];
RightC := Hexes[Right];
WRITE(LeftC,RightC,' ');
LineSize := LineSize + 3;
IF LineSize >= Width THEN
BEGIN
WRITELN('');
LineSize := 0;
END;
END; {For}
WRITELN('');
END; {HexDump}
(*********************************************************************)